<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
                 label-width="68px">
            <el-form-item label="项目id" prop="projectId">
                <el-input v-model="queryParams.projectId" placeholder="请输入项目id"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="项目编号" prop="projectCode">
                <el-input v-model="queryParams.projectCode" placeholder="请输入项目编号"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="订单id" prop="orderId">
                <el-input v-model="queryParams.orderId" placeholder="请输入订单id"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="工单id" prop="workOrderId">
                <el-input v-model="queryParams.workOrderId" placeholder="请输入工单id"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="工单code" prop="workOrderCode">
                <el-input v-model="queryParams.workOrderCode" placeholder="请输入工单code"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="材料" prop="materialId">
                <el-input v-model="queryParams.materialId" placeholder="请输入材料"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="产品id" prop="goodsId">
                <el-input v-model="queryParams.goodsId" placeholder="请输入产品id"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="产品到货id" prop="daohuoDetailId">
                <el-input v-model="queryParams.daohuoDetailId" placeholder="请输入产品到货id"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="入库id" prop="rukuId">
                <el-input v-model="queryParams.rukuId" placeholder="请输入入库id"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="生产明细id" prop="produceRecordDetailId">
                <el-input v-model="queryParams.produceRecordDetailId" placeholder="请输入生产明细id"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="发货明细id" prop="fahuoDetailId">
                <el-input v-model="queryParams.fahuoDetailId" placeholder="请输入发货明细id"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="抽样id" prop="sampleId">
                <el-input v-model="queryParams.sampleId" placeholder="请输入抽样id"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="产品编号" prop="goodsCode">
                <el-input v-model="queryParams.goodsCode" placeholder="请输入产品编号"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="订单编号" prop="orderCode">
                <el-input v-model="queryParams.orderCode" placeholder="请输入订单编号"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="订单产品关联id" prop="goodsSaleId">
                <el-input v-model="queryParams.goodsSaleId" placeholder="请输入订单产品关联id"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="名称" prop="name">
                <el-input v-model="queryParams.name" placeholder="请输入名称"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="检验编号" prop="inspectNumber">
                <el-input v-model="queryParams.inspectNumber" placeholder="请输入检验编号"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="原材料制造商" prop="producer">
                <el-input v-model="queryParams.producer" placeholder="请输入原材料制造商"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="牌号" prop="code">
                <el-input v-model="queryParams.code" placeholder="请输入牌号"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="炉批号" prop="heatBatchNumber">
                <el-input v-model="queryParams.heatBatchNumber" placeholder="请输入炉批号"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="来料检验批次号" prop="batchNumber">
                <el-input v-model="queryParams.batchNumber" placeholder="请输入来料检验批次号"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
                        <el-form-item label="出厂检测日期" prop="leaveInspectDate">
                            <el-date-picker clearable v-model="queryParams.leaveInspectDate"
                                            type="date" value-format="yyyy-MM-dd" placeholder="请选择出厂检测日期">
                            </el-date-picker>
                        </el-form-item>
                        <el-form-item label="入厂检测日期" prop="arriveInspectDate">
                            <el-date-picker clearable v-model="queryParams.arriveInspectDate"
                                            type="date" value-format="yyyy-MM-dd" placeholder="请选择入厂检测日期">
                            </el-date-picker>
                        </el-form-item>
            <el-form-item label="机械性能-抗拉强度" prop="tensileStrength">
                <el-input v-model="queryParams.tensileStrength" placeholder="请输入机械性能-抗拉强度"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="屈服强度" prop="succumbStrength">
                <el-input v-model="queryParams.succumbStrength" placeholder="请输入屈服强度"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="机械性能-断后伸长率" prop="extend">
                <el-input v-model="queryParams.extend" placeholder="请输入机械性能-断后伸长率"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="机械性能-硬度" prop="hardness">
                <el-input v-model="queryParams.hardness" placeholder="请输入机械性能-硬度"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="拉伸强度" prop="pullStrength">
                <el-input v-model="queryParams.pullStrength" placeholder="请输入拉伸强度"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="延伸率" prop="extendRate">
                <el-input v-model="queryParams.extendRate" placeholder="请输入延伸率"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="力学性能-单丝强度" prop="singleStrength">
                <el-input v-model="queryParams.singleStrength" placeholder="请输入力学性能-单丝强度"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="质检是否通过" prop="testPass">
                <el-input v-model="queryParams.testPass" placeholder="请输入质检是否通过"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                        v-hasPermi="['develop:FactoryTestMachineryCommon:add']">新增</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single"
                        @click="handleUpdate" v-hasPermi="['develop:FactoryTestMachineryCommon:edit']">修改</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-popconfirm title="确认删除选择的数据项？" @confirm="handleDelete({})">
                    <el-button slot="reference" type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
                               v-hasPermi="['develop:FactoryTestMachineryCommon:remove']">删除</el-button>
                </el-popconfirm>
            </el-col>
            <el-col :span="1.5">
                <el-button type="warning" plain icon="el-icon-download" size="mini"
                        @click="handleExport" v-hasPermi="['develop:FactoryTestMachineryCommon:export']">导出</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table border v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" ref="table" :max-height="tableMaxHeight">
            <el-table-column type="selection" width="55" align="center"/>
                    <el-table-column label="主键" align="center" prop="id"/>
            <el-table-column label="项目id" align="center" prop="projectId"/>
            <el-table-column label="项目编号" align="center" prop="projectCode"/>
            <el-table-column label="订单id" align="center" prop="orderId"/>
            <el-table-column label="工单id" align="center" prop="workOrderId"/>
            <el-table-column label="工单code" align="center" prop="workOrderCode"/>
            <el-table-column label="材料" align="center" prop="materialId"/>
            <el-table-column label="产品id" align="center" prop="goodsId"/>
            <el-table-column label="产品到货id" align="center" prop="daohuoDetailId"/>
            <el-table-column label="入库id" align="center" prop="rukuId"/>
            <el-table-column label="生产明细id" align="center" prop="produceRecordDetailId"/>
            <el-table-column label="发货明细id" align="center" prop="fahuoDetailId"/>
            <el-table-column label="抽样id" align="center" prop="sampleId"/>
            <el-table-column label="产品编号" align="center" prop="goodsCode"/>
            <el-table-column label="订单编号" align="center" prop="orderCode"/>
            <el-table-column label="订单产品关联id" align="center" prop="goodsSaleId"/>
            <el-table-column label="名称" align="center" prop="name"/>
            <el-table-column label="检验编号" align="center" prop="inspectNumber"/>
            <el-table-column label="材料类别" align="center" prop="type"/>
            <el-table-column label="原材料制造商" align="center" prop="producer"/>
            <el-table-column label="牌号" align="center" prop="code"/>
            <el-table-column label="炉批号" align="center" prop="heatBatchNumber"/>
            <el-table-column label="来料检验批次号" align="center" prop="batchNumber"/>
                    <el-table-column label="出厂检测日期" align="center" prop="leaveInspectDate" width="180">
                        <template slot-scope="scope">
                            <span>{{ parseTime(scope.row.leaveInspectDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="入厂检测日期" align="center" prop="arriveInspectDate" width="180">
                        <template slot-scope="scope">
                            <span>{{ parseTime(scope.row.arriveInspectDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                        </template>
                    </el-table-column>
            <el-table-column label="机械性能-抗拉强度" align="center" prop="tensileStrength"/>
            <el-table-column label="屈服强度" align="center" prop="succumbStrength"/>
            <el-table-column label="机械性能-断后伸长率" align="center" prop="extend"/>
            <el-table-column label="机械性能-硬度" align="center" prop="hardness"/>
            <el-table-column label="拉伸强度" align="center" prop="pullStrength"/>
            <el-table-column label="延伸率" align="center" prop="extendRate"/>
            <el-table-column label="力学性能-单丝强度" align="center" prop="singleStrength"/>
            <el-table-column label="质检是否通过" align="center" prop="testPass"/>
            <el-table-column label="检测结果" align="center" prop="result"/>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-edit"
                            @click="handleUpdate(scope.row)" v-hasPermi="['develop:FactoryTestMachineryCommon:edit']">修改</el-button>
                    <el-popconfirm :title="`确认删除当前数据项？`" @confirm="handleDelete(scope.row)"
                                   style="margin-left: 10px;">
                        <el-button slot="reference" size="mini" type="text" icon="el-icon-delete"
                                   v-hasPermi="['develop:FactoryTestMachineryCommon:remove']">删除</el-button>
                    </el-popconfirm>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList"/>

        <factoryTestMachineryCommon-form ref="form" @ok="getList"></factoryTestMachineryCommon-form>
    </div>
</template>

<script>
    import { deleteAction, getAction } from '@/api/manage'
    import FactoryTestMachineryCommonForm from '@/views/develop/factory/factoryTestMachineryCommon/module/FactoryTestMachineryCommonForm'

    export default {
        name: "FactoryTestMachineryCommonList",
        components: {
            FactoryTestMachineryCommonForm,
        },
        data() {
            return {
                // 遮罩层
                loading: true,
                // 选中数组
                ids: [],
                // 非单个禁用
                single: true,
                // 非多个禁用
                multiple: true,
                // 显示搜索条件
                showSearch: true,
                // 总条数
                total: 0,
                // 通用机械试验表格数据
                dataList: [],
                // 查询参数
                queryParams: {
                    pageNum: 1,
                    pageSize: 10,
            projectId: null,
            projectCode: null,
            orderId: null,
            workOrderId: null,
            workOrderCode: null,
            materialId: null,
            goodsId: null,
            daohuoDetailId: null,
            rukuId: null,
            produceRecordDetailId: null,
            fahuoDetailId: null,
            sampleId: null,
            goodsCode: null,
            orderCode: null,
            goodsSaleId: null,
            name: null,
            inspectNumber: null,
            type: null,
            producer: null,
            code: null,
            heatBatchNumber: null,
            batchNumber: null,
            leaveInspectDate: null,
            arriveInspectDate: null,
            tensileStrength: null,
            succumbStrength: null,
            extend: null,
            hardness: null,
            pullStrength: null,
            extendRate: null,
            singleStrength: null,
            testPass: null,
            result: null,
                },
                url: {
                    list:'/factoryTestMachineryCommon/factoryTestMachineryCommon/list',
                    remove:'/factoryTestMachineryCommon/factoryTestMachineryCommon/',
                    export:'/factoryTestMachineryCommon/factoryTestMachineryCommon/export',
                },
                tableMaxHeight: window.innerHeight - 320,
            };
        },
        created() {
            this.getList();
            window.addEventListener('resize', this.getTableHeight);
        },
        destroyed () {
            window.removeEventListener('resize', this.getTableHeight)
        },
        methods: {
            /** 查询通用机械试验列表 */
            getList() {
                this.loading = true;
                getAction(this.url.list, this.queryParams).then(response => {
                    this.dataList = response.rows;
                    this.total = response.total;
                    this.loading = false;
                });
            },
            getTableHeight () {
                this.tableHeight = window.innerHeight - 320
            },
            /** 搜索按钮操作 */
            handleQuery() {
                this.queryParams.pageNum = 1;
                this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.resetForm("queryForm");
                this.handleQuery();
            },
            // 多选框选中数据
            handleSelectionChange(selection) {
                this.ids = selection.map(item => item.id)
                this.single = selection.length !== 1
                this.multiple = !selection.length
            },
            /** 新增按钮操作 */
            handleAdd() {
                this.$refs.form.handleAdd();
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.$refs.form.handleUpdate(row);
            },
            /** 删除按钮操作 */
            handleDelete(row) {
                const ids = row.id || this.ids;
                deleteAction(this.url.remove, ids).then(response => {
                    this.getList();
                    this.$modal.msgSuccess("删除成功");
                }).catch(() => {});
            },
            /** 导出按钮操作 */
            handleExport() {
                this.download(this.url.export, {
                    ...this.queryParams
                }, `factoryTestMachineryCommon_${new Date().getTime()}.xlsx`)
            },
  }
};
</script>
